import type {
  CalendarInputProps,
  CheckboxGroupProps,
  CheckboxInputProps,
  DatetimePickerInputProps,
  FormItemProps,
  FormRules,
  InputProps,
  PickerProps,
  PopoutProps,
  RadioGroupProps,
  RadioInputProps,
  RateProps,
  SliderProps,
  StepperProps,
  SwitchProps,
  UploadProps,
} from 'sard-uniapp'
import type { Rule } from 'sard-uniapp/components/form/Validator'

import type GiForm from './gi-form.vue'

export type ColumnItemType =
  | 'input'
  | 'textarea'
  | 'picker'
  | 'stepper'
  | 'datetime-picker'
  | 'calendar'
  | 'checkbox-group'
  | 'checkbox-input'
  | 'radio-group'
  | 'radio-input'
  | 'popout-input'
  | 'rate'
  | 'slider'
  | 'switch'
  | 'upload'
  | 'group-title'

export type ColumnItemProps =
  & InputProps
  & StepperProps
  & PickerProps
  & DatetimePickerInputProps
  & CalendarInputProps
  & CheckboxGroupProps
  & CheckboxInputProps
  & RadioGroupProps
  & RadioInputProps
  & PopoutProps
  & RateProps
  & SliderProps
  & SwitchProps
  & UploadProps

export type ColumnItemHide<F> = boolean | ((form: F) => boolean)
export type ColumnDisabled<F> = boolean | ((form: F) => boolean)
export type ColumnItemReadonly<F> = boolean | ((form: F) => boolean)

export interface ColumnItem<F = any> {
  type: ColumnItemType
  label: string
  field: string
  fcKey?: string // 表单控制的key
  props?: ColumnItemProps
  formItemProps?: FormItemProps
  hide?: ColumnItemHide<F> // 是否隐藏
  disabled?: ColumnDisabled<F>
  readonly?: ColumnItemReadonly<F> // 是否只读
  rules?: Rule[]
  coverRules?: FormRules
  slotName?: string
}

export type GiFormInstance = InstanceType<typeof GiForm>
